/*
Created by Marcus Ruether
4-1-08
*/

enum opcode {ADD, SUB, MOV, MULT, DIV, JNZ, JNEQ, JEQ, BR, JGT, JLT, GET, PUT, PUTC, FINISH};
enum regi {A, R1, R2, R3, R4, R5, R6, R7};
enum lexeme {INTEGER, FLOAT, REGI, OPCODE, JUNK, SPACE, COMMENT};
//holds token value
union value
{
	int i;
	float f;
	int r;
	enum opcode op;
};

//stores valid "tokens"
struct token
{
	union value v;
	enum lexeme type;
	struct token *next;
	int lineNumb;
	char strVal[30];
};

//linked list of tokens
struct tokenList
{
	struct token *head;
	struct token *tail;
};
//creates a new token to store valid values
struct token *new_token();

//creates s singly linked list for storing tokens
struct tokenList *new_tokenList();

//adds token to tokenList
void push_token(struct tokenList *tokenList ,struct token *newToken);

//deletes a token list
void delete_tokenList(struct tokenList *t);

//Tokenizes input stream line by line.  Checks if any of them are valid lexams
//if they are then they are added to tokenList, and printed to OUT
//if they are invalid, the value and linenumber are print to ERR
//Operations is an array of tokenList that contain operations to be executed
//numOfOps is the size of the Operations array(the last index + 1). 
void lex_main(FILE *IN, FILE *OUT, FILE *ERR, struct tokenList *Operations [], int numOfOps);

//called my lex_main, checks if floar
int is_float(char *floattest);

//called my lex_main, checks if int
int is_int(char *inttest);

//called my lex_main, checks if register
//if it is a register, return that register value
int is_regi(char *regtest);

//called my lex_main, checks if opcode
//if it is an opcode, return that opcode value
enum opcode is_opcode(char *optest);

// From http://www.siafoo.net/snippet/75
//Last updated by schram  on 2008-03-27 10:47 (ver. 2)
//fgetstr() - mimics behavior of fgets(), but removes new-line
//   character at end of line if it exists
char *fgetstr(char *string,int n ,FILE *stream);
